<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<%
String path = request.getContextPath();

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
    <link rel="stylesheet" href="<%=path%>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/cupertino/jquery-ui.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<%=path%>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<%=path%>/js/jquery.jqGrid.min.js"></script>
    <style>
html, body {
	margin: 0;			 
	padding: 0;
	 
    font-size: 85%;
}
</style>
    
  </head>
    <script type="text/javascript"> 
    var lastsel; 
    var data;
  function loadTab(){ 
  var xtdh = '${xtdh}'; 
  var bblx = '${bblx}';
  //alert(bblx);
      if(bblx==1){
      loadDayTab(xtdh);
      }
      else if(bblx==2){
      loadMonthTab(xtdh);
      }
      else if(bblx==3){
      loadNoteTab(xtdh);
      }
  }
  
  function loadDayTab(xtdh){
  //alert(xtdh);
      $("#myTab").jqGrid({      
    url:'<%=path%>/bbgl/findTempBbJgrid.action?bblx=1&xtdh='+xtdh,   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['上报日期','合同编号', '签订量','本日执行车数','本日执行运量','累计执行车数','累计执行运量','出省站','备注','验证信息'],
   	colModel:[
   		{name:'sbrq',index:'sbrq', width:80},
   		{name:'qyhth',index:'qyhth', width:90,editable:true},
   		{name:'qdsl',index:'qdsl', width:60,align:"right",editable:true},		
   		{name:'brcs',index:'brcs', width:80,align:"right",editable:true},	
   		{name:'bryl',index:'bryl', width:80,align:"right",editable:true},	
   		{name:'ljcs',index:'ljcs', width:80,align:"right",editable:true},	
   		{name:'ljyl',index:'ljyl', width:80,align:"right",editable:true},
   		{name:'chusz',index:'chusz', width:50,editable:true},
   		{name:'beiz',index:'beiz', width:150, sortable:false,editable:true},
   		{name:'jyjg',index:'jyjg', width:120}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'sysid'
         }, 
    width: 1070, 
    shrinkToFit:false,   	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager13',
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    sortorder: 'desc',
	caption: "列表",
	//gridComplete:function()
	//{ //在此事件中循环为每一行添加修改和删除链接 	
		//var ids=$("#myTab").jqGrid('getDataIDs'); 
		//alert(ids);
		//for(var j=0; j<ids.length; j++)
		//{		
		//     id=ids[j];		    
		//	 verify="<a href='#' style='color:#f60' onclick='modify("+ id +")'>编辑</a>";
		//	$("#myTab").jqGrid('setRowData',id, { modify: verify }); 
			
		//}
	//}	
	onSelectRow: function(id){				
     if(id && id !== lastsel){    
     $('#myTab').jqGrid('editRow',id,{  
         keys : true,        //这里按[enter]保存  
         url: "<%=path%>/bbgl/modifyTempBbJgrid.action",  
         mtype : "POST",  
         restoreAfterError: true,  
         extraparam: {
             "bblx":1,
             "xtdh":xtdh,  
             "sysid":id,  
             "qyhth":$("#"+id+"_qyhth").val(),
             "qdsl":$("#"+id+"_qdsl").val(),
             "brcs":$("#"+id+"_brcs").val(),
             "bryl":$("#"+id+"_bryl").val(),
             "ljcs":$("#"+id+"_ljcs").val(),
             "ljyl":$("#"+id+"_ljyl").val(),
             "chusz":$("#"+id+"_chusz").val(),
             "beiz":$("#"+id+"_beiz").val()                      
         },      
         succesfunc: function(response){  
             alert("save success");  
             return true;  
         }
         
         });  
      } 		 
	} 		
  });
  $("#myTab").jqGrid('setGridHeight','300px');
  }

  
  function loadMonthTab(xtdh){
  //alert(xtdh);
      $("#myTab").jqGrid({      
    url:'<%=path%>/bbgl/findTempBbJgrid.action?bblx=2&xtdh='+xtdh,   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['上报日期','合同编号','签订量','本月执行量','累计执行量','出省站','备注','验证信息'],
   	colModel:[
   		{name:'sbrq',index:'sbrq', width:80},
   		{name:'qyhth',index:'qyhth', width:90,editable:true},
   		{name:'qdsl',index:'qdsl', width:80,align:"right",editable:true},
   		{name:'byzxl',index:'byzxl', width:120,align:"right",editable:true},		
   		{name:'ljzxl',index:'ljzxl', width:120,align:"right",editable:true},
   		{name:'chusz',index:'chusz', width:120,editable:true},
   		{name:'beiz',index:'beiz', width:150, sortable:false,editable:true},
   		{name:'jyjg',index:'jyjg', width:120}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'sysid'
         },
    width: 1070, 
    shrinkToFit:false,    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager13',
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    sortorder: 'desc',
	caption: "列表",	
	onSelectRow: function(id){				
     if(id && id !== lastsel){    
     $('#myTab').jqGrid('editRow',id,{  
         keys : true,        //这里按[enter]保存  
         url: "<%=path%>/bbgl/modifyTempBbJgrid.action",  
         mtype : "POST",  
         restoreAfterError: true,  
         extraparam: {
             "bblx":2,
             "xtdh":xtdh,  
             "sysid":id,  
             "qyhth":$("#"+id+"_qyhth").val(),
             "byzxl":$("#"+id+"_byzxl").val(),
             "ljzxl":$("#"+id+"_ljzxl").val(),
             "chusz":$("#"+id+"_chusz").val(),
             "beiz":$("#"+id+"_beiz").val()                        
         },      
         succesfunc: function(response){  
             alert("save success");  
             return true;  
         }
         
         });  
      } 		 
	}		
  });
  $("#myTab").jqGrid('setGridHeight','300px');
  }
  
  function loadNoteTab(xtdh){
  //alert(xtdh);
      $("#myTab").jqGrid({      
    url:'<%=path%>/bbgl/findTempBbJgrid.action?bblx=3&xtdh='+xtdh,   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['上报日期','地市','出省累计份数','出省累计运量','出省本月份数','出省本月运量', '省内累计份数','省内累计运量','省内本月份数','省内本月运量','电煤累计份数','电煤累计运量','电煤本月份数','电煤本月运量','验证信息'],
   	colModel:[
   		{name:'sbrq',index:'sbrq', width:80},
   		{name:'dishi',index:'dishi', width:40},
   		{name:'csljfs',index:'csljfs', width:80,editable:true},
   		{name:'csljyl',index:'csljyl', width:80,editable:true},
   		{name:'csbyfs',index:'csbyfs', width:80,editable:true},
   		{name:'csbyyl',index:'csbyyl', width:80,editable:true},   		
   		{name:'snljfs',index:'snljfs', width:80,editable:true},
   		{name:'snljyl',index:'snljyl', width:80,editable:true},
   		{name:'snbyfs',index:'snbyfs', width:80,editable:true},
   		{name:'snbyyl',index:'snbyyl', width:80,editable:true},   		
   		{name:'dmljfs',index:'dmljfs', width:80,editable:true},
   		{name:'dmljyl',index:'dmljyl', width:80,editable:true},
   		{name:'dmbyfs',index:'dmbyfs', width:80,editable:true},
   		{name:'dmbyyl',index:'dmbyyl', width:80,editable:true},
   		{name:'jyjg',index:'jyjg', width:120}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'sysid'
         }, 
    width: 1070, 
    shrinkToFit:false,   	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager13',
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    sortorder: 'desc',
	caption: "列表",
	onSelectRow: function(id){				
     if(id && id !== lastsel){    
     $('#myTab').jqGrid('editRow',id,{  
         keys : true,        //这里按[enter]保存  
         url: "<%=path%>/bbgl/modifyTempBbJgrid.action",  
         mtype : "POST",  
         restoreAfterError: true,  
         extraparam: {
             "bblx":3,
             "xtdh":xtdh,  
             "sysid":id,
             "csljfs":$("#"+id+"_csljfs").val(),
             "csljyl":$("#"+id+"_csljyl").val(),
             "csbyfs":$("#"+id+"_csbyfs").val(),
             "csbyyl":$("#"+id+"_csbyyl").val(),
             "snljfs":$("#"+id+"_snljfs").val(),
             "snljyl":$("#"+id+"_snljyl").val(),
             "snbyfs":$("#"+id+"_snbyfs").val(),
             "snbyyl":$("#"+id+"_snbyyl").val(),
             "dmljfs":$("#"+id+"_dmljfs").val(),
             "dmljyl":$("#"+id+"_dmljyl").val(),
             "dmbyfs":$("#"+id+"_dmbyfs").val(),
             "dmbyyl":$("#"+id+"_dmbyyl").val()                        
         },      
         succesfunc: function(response){  
             alert("save success");  
             return true;  
         }
         
         });  
      } 		 
	}	
  });
  $("#myTab").jqGrid('setGridHeight','300px');
  }

    $(function(){ 
    $("#jiaoy").button(); 
    $("#daor").button();
    $("#shanc").button();
    $("#daoc").button();
    $("#dialog-confirm").hide();
    $("#dialog-confirm1").hide(); 
    $("#dialog-confirm2").hide();
    loadTab();    
    queryNum();
     $( "#tabs" ).tabs({
				    select: function(event, ui) {
				    
		  		  }	});
 });

// 查询
function search(){   
  var formdata = $("#form1").serialize();  
  $("#myTab").jqGrid('setGridParam',{url:'findTempBbJgrid.action?'+formdata,mtype:'post',page:1}).trigger("reloadGrid"); 
}

function Verify(id) { //单击修改链接的操作 
   if(id.id!=undefined){
   openwindow('<%=path %>/htgl/rchtxgInfo.action?htbh='+id.id);
   }else{
   var htbh = id.item(1).cells.item(2).innerHTML;
	openwindow('<%=path %>/htgl/rchtxgInfo.action?htbh='+htbh );
   }
}

function checkRow(){
  var xtdh = '${xtdh}'; 
  var url = "<%=path%>/bbgl/checkBbxxInfo.action?bblx=${bblx}&xtdh="+xtdh;
  //alert(url);
	$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				    
					$.post(url, function(data) {					
                    var json =eval('(' + data + ')');
					   if(json.result==1){					   
					   alert("校验完成！");
					   window.location.reload(true);
					   }else{					  
					   alert("校验失败！");
					   }   
                   });                  
                   $( this ).dialog( "close" );
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		}); 
}

function impRow(){
  var xtdh = '${xtdh}'; 
  var url = "<%=path%>/bbgl/impBbxxInfo.action?bblx=${bblx}&xtdh="+xtdh;
  //alert(url);
	$( "#dialog-confirm1" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {				    
					$.post(url, function(data) {					
                    var json =eval('(' + data + ')');
					   if(json.result==1){					   
					   alert("导入成功！");
					   window.location.reload(true);
					   }else{					  
					   alert("导入失败！");
					   }   
                   });                  
                   $( this ).dialog( "close" );
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		}); 
}

function removeRow() {
	var s = $("#myTab").jqGrid('getGridParam','selarrrow');
	alert(s);
	if (s == "") {
        alert("请先选择报单，再点击删除！");
        return;
    }	
	var url = "<%=path%>/bbgl/removeBbxxInfo.action?bblx=${bblx}&xtdh=${xtdh}&sysid="+s;
	$( "#dialog-confirm2" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
					var json =eval('(' + data + ')');
					if(json.result==1){
					   alert("删除成功！");
					   window.location.reload(true);
					   //reloadhtxx();
					}else{
					   alert("删除失败！");
					}
                                                       
                   });                    
                   $( this ).dialog( "close" ); 
                   
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function expExcel(){ 
	form1.action="<%=path%>/bbgl/expExcelForTemp.action?bblx=${bblx}&xtdh=${xtdh}";
	form1.method = "post";
	form1.submit();
}

//计算成交金额函数
		function queryNum(){ 
		      var xtdh = '${xtdh}'; 
              var url = "<%=path%>/bbgl/queryNum.action?bblx=${bblx}&xtdh="+xtdh;  
			  var formdata = $("#form1").serialize(); 
			  $.post(url,formdata,function(data,textStatus)
			  {			  
			  var json = eval('(' + data + ')');			
			  var re=/(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
			  var bblx = '${bblx}';  
              if(bblx==1){
              if (json[0].ds !="")
               {
			     $("#queryNum").html("合计 单数："+json[0].ds + "条  签订量："+json[0].qdsl.toString().replace(re,"$1,")+"万吨  本日执行车数："+json[0].brcs.toString().replace(re,"$1,")+"车 本日执行运量："+json[0].bryl.toString().replace(re,"$1,")+"万吨 累计执行车数："+json[0].ljcs.toString().replace(re,"$1,")+"车 累计执行运量："+json[0].ljyl.toString().replace(re,"$1,")+"万吨");
			   } else
                 {
                 $("#queryNum").html("合计 单数：0 条  签订量： 0 万吨  本日执行车数：0 车 本日执行运量：0 万吨 累计执行车数：0 车 累计执行运量：0 万吨");                 
                 }                
              }
              if(bblx==2){
              if (json[0].ds !="")
               {
			     $("#queryNum").html("合计 单数："+json[0].ds + "条  签订量："+json[0].qdsl.toString().replace(re,"$1,")+"万吨  本月执行量："+json[0].byzxl.toString().replace(re,"$1,")+"万吨  累计执行量："+json[0].ljzxl.toString().replace(re,"$1,")+"万吨");
			   } else
                 {
                 $("#queryNum").html("合计 单数：0 条  签订量： 0 万吨  本月执行量：0 万吨 累计执行量：0 万吨");                 
                 }                 
              }
              if(bblx==3){
              if (json[0].ds !="")
               {
			     $("#queryNum").html("出省累计份数："+json[0].csljfs.toString().replace(re,"$1,") + "份  出省累计运量："+json[0].csljyl.toString().replace(re,"$1,")+"吨  出省本月份数："+json[0].csbyfs.toString().replace(re,"$1,")+"份  出省本月运量："+json[0].csbyyl.toString().replace(re,"$1,")+"吨  <br>省内累计份数："+json[0].snljfs.toString().replace(re,"$1,") + "份  省内累计运量："+json[0].snljyl.toString().replace(re,"$1,")+"吨  省内本月份数："+json[0].snbyfs.toString().replace(re,"$1,")+"份  省内本月运量："+json[0].snbyyl.toString().replace(re,"$1,")+"吨 <br>电煤累计份数："+json[0].dmljfs.toString().replace(re,"$1,") + "份  电煤累计运量："+json[0].dmljyl.toString().replace(re,"$1,")+"吨  电煤本月份数："+json[0].dmbyfs.toString().replace(re,"$1,")+"份  电煤本月运量："+json[0].dmbyyl.toString().replace(re,"$1,")+"吨");
			   } else
                 {
                 $("#queryNum").html("合计 单数：0 条  车数： 0 车  吨数：0 吨");                 
                 }             
                
              }
                 });  
               }       
               

</script>
<body>  
<div id="best1">
  <form name="form1" method="post">
  <table id="list_search" cellpadding="0" cellspacing="0" border="0">
    <tr>
		    <td align="left">
		    <s:if test="bblx!=3">		    
		    <input id="jiaoy" type="button" value="校验"  onclick="checkRow();"/>&nbsp;&nbsp;
		    </s:if>
		    <input id="daor" type="button" value="全部提报" onclick="impRow();"/>&nbsp;&nbsp;
		    <input id="shanc" type="button"  value="删除" onclick="removeRow();" />&nbsp;&nbsp;
		    <input id="daoc" type="button"  value="导出EXCEL" onclick="expExcel();" />
		    &nbsp;&nbsp;&nbsp;&nbsp;
		    <s:if test="bblx!=3">
		    <span style="color: red;font-size:12px;vertical-align:middle;">友情提示：*请先[校验]之后再[提报]</span>
		    </s:if>
		    </td>     
            
        </tr>
    </table>
    </form>
    <div id="tabs">
      <ul>
            <li id="queryNum" style="float:left; vertical-align: bottom; line-height:23px; "></li>					
	   </ul>
    <table id="myTab" class="scroll" cellpadding="0" cellspacing="0"></table>  
   <div id="pager13" class="scroll"></div>  
   <div id="message" class="scroll"></div>
   </div> 
</div> 
<div id="dialog-confirm" title="消息提示"><strong>是否确认校验？</strong></div>
<div id="dialog-confirm1" title="消息提示"><strong>是否确认导入？</strong></div>
<div id="dialog-confirm2" title="消息提示"><strong>是否确认删除？</strong></div>
</body>
</html>
